#include <iostream>

using namespace std;

const int N = 200;

int n;
char root;
char l[N], r[N];

//先序遍历
void dfs(char u)
{
	cout << u;
	if(l[u] != '*') dfs(l[u]);
	if(r[u] != '*') dfs(r[u]);
}

int main()
{
	cin >> n;
	//处理根节点
	cin >> root;
	cin >> l[root] >> r[root];

	for(int i = 2; i <= n; i++)
	{
		char t; cin >> t;
		cin >> l[t] >> r[t];
	}

	dfs(root);

	return 0;
}
